package com.kantboot.system.user.web.controller;

import com.kantboot.system.user.domain.vo.LoginVO;
import com.kantboot.system.user.service.ISysLoginService;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system-user-web/login")
public class LoginController {

    @Resource
    private ISysLoginService service;

    /**
     * 注册（不建议使用，建议使用安全的注册接口）
     * @param username 用户名
     * @param password 密码
     * @return token
     */
    @PostMapping("/register")
    public RestResult<LoginVO> register(
            @RequestParam("username") String username,
            @RequestParam("password") String password) {
        return RestResult.success(service.register(username, password),"registerSuccess","注册成功");
    }

    /**
     * 登录（不建议使用，建议使用安全的登录接口）
     * @param username 用户名
     * @param password 密码
     * @return token
     */
    @PostMapping("/login")
    public RestResult<LoginVO> login(
            @RequestParam("username") String username,
            @RequestParam("password") String password) {
        return RestResult.success(service.login(username, password),"loginSuccess","登录成功");
    }

    /**
     * 注册（安全）
     * @param username 用户名
     * @param password 密码
     * @return token
     */
    @PostMapping("/registerWithSecurity")
    public RestResult<LoginVO> registerWithSecurity(
            @RequestParam("username") String username,
            @RequestParam("password") String password) {
        return RestResult.success(service.registerWithSecurity(username, password),"registerSuccess","注册成功");
    }

    /**
     * 登录（安全）
     * @param username 用户名
     * @param password 密码
     * @return token
     */
    @PostMapping("/loginWithSecurity")
    public RestResult<LoginVO> loginWithSecurity(
            @RequestParam("username") String username,
            @RequestParam("password") String password) {
        return RestResult.success(service.loginWithSecurity(username, password),"loginSuccess","登录成功");
    }

    /**
     * 登出
     */
    @PostMapping("/logout")
    public RestResult<Void> logout() {
        service.logout();
        return RestResult.success(null,"logoutSuccess","退出登录成功");
    }

    /**
     * 手机号+密码登录（不建议使用，建议使用安全的登录接口）
     * @param phone 手机号
     * @param password 密码
     * @return token
     */
    @PostMapping("/loginWithPhoneAndPassword")
    public RestResult<LoginVO> loginWithPhoneAndPassword(
            @RequestParam("phone") String phone,
            @RequestParam("password") String password) {
        return RestResult.success(service.loginWithPhoneAndPassword(phone, password),"loginSuccess","登录成功");
    }

    /**
     * 手机号+密码登录（安全）
     * @param phone 手机号
     * @param password 密码
     * @return token
     */
    @PostMapping("/loginWithPhoneAndPasswordWithSecurity")
    public RestResult<LoginVO> loginWithPhoneAndPasswordWithSecurity(
            @RequestParam("phone") String phone,
            @RequestParam("password") String password) {
        return RestResult.success(service.loginWithPhoneAndPasswordWithSecurity(phone, password),"loginSuccess","登录成功");
    }

    /**
     * 邮箱+密码登录（不建议使用，建议使用安全的登录接口）
     * @param email 邮箱
     * @param password 密码
     * @return token
     */
    @PostMapping("/loginWithEmailAndPassword")
    public RestResult<LoginVO> loginWithEmailAndPassword(
            @RequestParam("email") String email,
            @RequestParam("password") String password) {
        return RestResult.success(service.loginWithEmailAndPassword(email, password),"loginSuccess","登录成功");
    }

    /**
     * 邮箱+密码登录（安全）
     * @param email 邮箱
     * @param password 密码
     * @return token
     */
    @PostMapping("/loginWithEmailAndPasswordWithSecurity")
    public RestResult<LoginVO> loginWithEmailAndPasswordWithSecurity(
            @RequestParam("email") String email,
            @RequestParam("password") String password) {
        return RestResult.success(service.loginWithEmailAndPasswordWithSecurity(email, password),"loginSuccess","登录成功");
    }

    /**
     * 手机号+验证码登录
     * @param phone 手机号
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/loginWithPhoneAndVarCode")
    public RestResult<LoginVO> loginWithPhoneAndVarCode(
            @RequestParam("phone") String phone,
            @RequestParam("varCode") String varCode) {
        return RestResult.success(service.loginWithPhoneAndVarCode(phone, varCode),"loginSuccess","登录成功");
    }

    /**
     * 手机号+验证码登录（安全）
     * @param phone 手机号
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/loginWithPhoneAndVarCodeWithSecurity")
    public RestResult<LoginVO> loginWithPhoneAndVarCodeWithSecurity(
            @RequestParam("phone") String phone,
            @RequestParam("varCode") String varCode) {
        return RestResult.success(service.loginWithPhoneAndVarCodeWithSecurity(phone, varCode),"loginSuccess","登录成功");
    }

    /**
     * 邮箱+验证码登录
     * @param email 邮箱
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/loginWithEmailAndVarCode")
    public RestResult<LoginVO> loginWithEmailAndVarCode(
            @RequestParam("email") String email,
            @RequestParam("varCode") String varCode) {
        return RestResult.success(service.loginWithEmailAndVarCode(email, varCode),"loginSuccess","登录成功");
    }

    /**
     * 邮箱+验证码登录（安全）
     * @param email 邮箱
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/loginWithEmailAndVarCodeWithSecurity")
    public RestResult<LoginVO> loginWithEmailAndVarCodeWithSecurity(
            @RequestParam("email") String email,
            @RequestParam("varCode") String varCode) {
        return RestResult.success(service.loginWithEmailAndVarCodeWithSecurity(email, varCode),"loginSuccess","登录成功");
    }

    /**
     * 手机号+验证码注册
     * @param phone 手机号
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/registerWithPhoneAndVarCode")
    public RestResult<LoginVO> registerWithPhoneAndVarCode(
            @RequestParam("phone") String phone,
            @RequestParam("varCode") String varCode
            ,@RequestParam("password") String password) {
        return RestResult.success(service.registerWithPhoneAndVarCode(phone, varCode, password),"registerSuccess","注册成功");
    }

    /**
     * 手机号+验证码注册（安全）
     * @param phone 手机号
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/registerWithPhoneAndVarCodeWithSecurity")
    public RestResult<LoginVO> registerWithPhoneAndVarCodeWithSecurity(
            @RequestParam("phone") String phone,
            @RequestParam("varCode") String varCode
            ,@RequestParam("password") String password) {
        return RestResult.success(service.registerWithPhoneAndVarCodeWithSecurity(phone, varCode, password),"registerSuccess","注册成功");
    }

    /**
     * 邮箱+验证码注册
     * @param email 邮箱
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/registerWithEmailAndVarCode")
    public RestResult<LoginVO> registerWithEmailAndVarCode(
            @RequestParam("email") String email,
            @RequestParam("varCode") String varCode
            ,@RequestParam("password") String password) {
        return RestResult.success(service.registerWithEmailAndVarCode(email, varCode, password),"registerSuccess","注册成功");
    }

    /**
     * 邮箱+验证码注册（安全）
     * @param email 邮箱1
     * @param varCode 验证码
     * @return token
     */
    @PostMapping("/registerWithEmailAndVarCodeWithSecurity")
    public RestResult<LoginVO> registerWithEmailAndVarCodeWithSecurity(
            @RequestParam("email") String email,
            @RequestParam("varCode") String varCode
            ,@RequestParam("password") String password) {
        return RestResult.success(service.registerWithEmailAndVarCodeWithSecurity(email, varCode, password),"registerSuccess","注册成功");
    }


}
